#include <iostream>
#include <queue>
#include <stack>
#include <cmath>
using namespace std;

const int N = 1e6 + 10;

char a[N];
int sc[N];
int t;

struct node{
	int i,j,sk,t;
	bool operator < (const node& x)const{
		if(t != x.t) return t > x.t;
		else if(sk != x.sk) return sk > x.sk;
        else if(j != x.j) return j > x.j;
        else return i > x.i;
	}
};

priority_queue<node> heap;
stack<char> un;
stack<int> mp;

int main(){
	int n;
	cin >> n;
	for(int i = 1;i <= n;i++){
		cin >> a[i];
	}
	for(int i = 1;i <= n;i++){
		cin >> sc[i];
	}
	un.push(a[1]);
	mp.push(1);
	for(int i = 2;i <= n;i++){
		if(un.size()&&a[i] != un.top()){
			un.pop();
			heap.push({mp.top(),i,abs(sc[mp.top()]-sc[i]),++t});
			mp.pop(); 
		}
		else{
			un.push(a[i]);
			mp.push(i); 
		}
	}
	cout << heap.size() << endl;
	while(heap.size()){
		node t = heap.top();heap.pop();
		int i = t.i,j = t.j;
		cout << i << " " << j << endl;
	}
	return 0;
} 
